//
//  MCOrderDetailFootView.swift
//  StoreManage
//
//  Created by MC on 2017/12/21.
//  Copyright © 2017年 MC. All rights reserved.
//

import UIKit

class MCOrderDetailFootView: UIView {

    // 用model的形式赋值
    var model = MCOrderListFatherModel() {
        didSet {
            switch model.deliveryWay {
            case 1:
                self.isContact = true
                self.contactView.deliveryButton.setTitle(" 及时送", for: UIControlState.normal)
                self.contactView.deliveryButton.setImage(#imageLiteral(resourceName: "Order_inTimeToSend"), for: UIControlState.normal)
                
                break
            case 2:
                self.isContact = true
                
                if model.isSelfDelivery == 1 {
                    self.contactView.deliveryButton.setTitle(" 自提", for: UIControlState.normal)
                } else {
                    self.contactView.deliveryButton.setTitle(" 到店取", for: UIControlState.normal)
                    self.contactView.deliveryButton.setImage(#imageLiteral(resourceName: "Order_store"), for: UIControlState.normal)
                }
                
                
                break
            case 3:
                self.isContact = false
                self.contactView.deliveryButton.setTitle(" 快递送", for: UIControlState.normal)
                self.contactView.deliveryButton.setImage(#imageLiteral(resourceName: "Order_express"), for: UIControlState.normal)
                
                break
            default:
                break
            }
            
            // 尾部视图
            // 联系方式
            self.contactView.nameLabel.text = model.linkMan + " " + model.mobile
            self.contactView.addressLabel.text = model.province + model.city + model.area
            self.contactView.addressDetailLabel.text = model.address
            
            // 优惠券和订单总金额
            self.noteView.ticketHeadView.detailLabel.text = MCString_judgemantDecimalsIsZero(figure: model.promotiondiscount.intValue)
            self.noteView.orderAmountHeadView.detailLabel.text = MCString_judgemantDecimalsIsZero(figure: model.orderAmount.intValue)

            // 发票和备注
            self.noteView.invoiceHeadView.detailLabel.text = model.billheader
            self.noteView.invoiceMoneyView.detailLabel.text = MCString_judgemantDecimalsIsZero(figure: model.billMoney)
            
            if model.remark.isEmpty {
                model.remark = "暂无"
            }
            self.noteView.noteView.detailLabel.text = model.remark
        }
    }
    
    
    var isContact : Bool = false {  // 是否联系人 否则就是收货地址
        didSet {
            
            var height = 0

            if isContact {
                height = 43
            } else {
                height = 83
            }
            contactView.isContact = isContact

            contactView.snp.remakeConstraints { (make) ->Void in
                make.left.right.top.equalTo(self)
                make.height.equalTo(height)
            }
            
            noteView.snp.remakeConstraints { (make) ->Void in
                make.left.right.equalTo(self)
                make.height.equalTo(40 * 5)
                make.top.equalTo(contactView.snp.bottom).offset(5)
            }
        }
    }

    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.MCGray_light
        
        self.addSubview(contactView)

        self.addSubview(noteView)
    }
  
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    lazy var contactView: MCOrderDetailContactView = {
        let view = MCOrderDetailContactView()
        return view
    }()

    lazy var noteView: MCOrderDetailNoteView = {
        let view = MCOrderDetailNoteView()
        return view
    }()
}
